package com.xiumu.controller.blog;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiumu.common.core.page.PageQuery;
import com.xiumu.common.core.result.ResultJSON;
import com.xiumu.pojo.blog.dto.BlogCategoryDTO;
import com.xiumu.pojo.blog.entity.BlogCategory;
import com.xiumu.pojo.blog.query.BlogCategoryQuery;
import com.xiumu.service.blog.BlogCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 博客分类表 Controller
 *
 * @author XiuMu
 * @Date 2023-01-29 18:09:13
 */
@RestController
public class BlogCategoryController {

    @Autowired
    private BlogCategoryService blogCategoryService;

    /**
     * 分页查询
     * 可传递查询参数，按照某些字段分页查询
     *
     * @param pageQuery 分页条件，查询参数
     * @return
     */
    @PostMapping("/page/blogCategory")
    public ResultJSON<Page<BlogCategory>> page(@RequestBody PageQuery<BlogCategoryQuery, BlogCategory> pageQuery) {
        return ResultJSON.querySuccess(blogCategoryService.listPage(pageQuery));
    }

    /**
     * 查询全部
     * 可传递查询参数，按照某些字段查询
     *
     * @param blogCategory 查询条件
     * @return
     */
    @GetMapping("/blogCategory")
    public ResultJSON<List<BlogCategory>> list(BlogCategoryQuery blogCategory) {
        return ResultJSON.querySuccess(blogCategoryService.listByBlogCategory(blogCategory));
    }

    /**
     * 创建 blogCategory
     *
     * @param blogCategoryDTO blogCategory 信息
     * @return
     */
    @PostMapping("/blogCategory")
    public ResultJSON<Boolean> create(@Validated @RequestBody BlogCategoryDTO blogCategoryDTO) {
        return ResultJSON.createSuccess(blogCategoryService.create(blogCategoryDTO));
    }
    /**
     * 更新 blogCategory
     *
     * @param blogCategoryDTO blogCategory 信息
     * @return
     */
    @PutMapping("/blogCategory/{id}")
    public ResultJSON<Boolean> update(@PathVariable("id") Long id, @Validated @RequestBody BlogCategoryDTO blogCategoryDTO) {
        return ResultJSON.modifySuccess(blogCategoryService.updateById(blogCategoryDTO, id));
    }

    /**
     * 删除 blogCategory
     *
     * @param id ID
     * @return
     */
    @DeleteMapping("/blogCategory/{id}")
    public ResultJSON<Boolean> delete(@PathVariable("id") Long id) {
        return ResultJSON.deleteSuccess(blogCategoryService.deleteById(id));
    }
}
